// JavaScript Document
function OverStatus(lgc)
{
	var _this = this;
	
	_this.bg = undefined;
	_this.buttonM = undefined;
	_this.buttonG = undefined;
	//_this.musicButton = undefined;
	_this.mark = undefined;
	_this.scoreBoard = undefined;
	var sNode = undefined;
	
	LogicStatus.call(_this, lgc)
	
	_this.prepare = function(preStat){
	    //if(preStat == GAMING)
	    if(preStat == GAMING)
	    {
	        //alert("真蠢, 游戏结束");
	    sNode = _this.logic.sceneManager.createNode( _this.bg, 4);  
        _this.logic.sceneManager.addNode(sNode);
         sNode = _this.logic.sceneManager.createNode(_this.buttonG, 1);
        _this.logic.sceneManager.addNode(sNode);
        sNode = _this.logic.sceneManager.createNode(_this.buttonM, 1);
        _this.logic.sceneManager.addNode(sNode);
		
		_this.scoreBoard.update(marks);
		sNode = _this.logic.sceneManager.createNode(_this.scoreBoard, 1);
		_this.logic.sceneManager.addNode(sNode);  
		
//		var tmp = undefined;
//		tmp = _this.mark.CreateImgList(marks, _this.mark.imgSrc_);
//		for(var i = 0; i < tmp.length; i++)
//		{
//			sNode = _this.logic.sceneManager.createNode(tmp[i], 1);  
//        	_this.logic.sceneManager.addNode(sNode);
//		}
		//alert(_this.mark.CreateImgList(10));
        }
	}

	_this.update = function(){
		// 在这里实现物件的更新, 
	}
	
	_this.mouseClick = function(e){
	     var CanvasEle = document.getElementById("myCanvas");
        //alert(distanceCanvas.offsetLeft);
        var mouseX = e.clientX - CanvasEle.offsetLeft;
        var mouseY = e.clientY - CanvasEle.offsetTop;
        //alert(mouseX);
        if(mouseX > _this.buttonM.position.x && mouseX < (_this.buttonM.position.x+_this.buttonM.box.width) && mouseY > _this.buttonM.position.y && mouseY < (_this.buttonM.position.y+_this.buttonM.box.height))
           {
               //alert("我现在是gameOver");
			   marks = 0;   
               _this.clearUp();
               _this.logic.statusChange(MENU);
           }
        if(mouseX > _this.buttonG.position.x && mouseX < (_this.buttonG.position.x+_this.buttonG.box.width) && mouseY > _this.buttonG.position.y && mouseY < (_this.buttonG.position.y+_this.buttonG.box.height))
           {

			   marks = 0;     
               _this.clearUp();
               _this.logic.statusChange(GAMING);
		   }
	}
	
	   _this.mouseMove = function(e)
     {
       //鼠标移动
        var CanvasEle = document.getElementById("myCanvas");
        var mouseX = e.clientX - CanvasEle.offsetLeft;
        var mouseY = e.clientY - CanvasEle.offsetTop;
        //alert(mouseX);
        if (mouseX > _this.buttonG.position.x && mouseX < (_this.buttonG.position.x+_this.buttonG.box.width) && mouseY > _this.buttonG.position.y && mouseY < (_this.buttonG.position.y+_this.buttonG.box.height))
        {
           _this.buttonG.changeIn();
         }
        if (mouseX < _this.buttonG.position.x || mouseX > (_this.buttonG.position.x+_this.buttonG.box.width) || mouseY < _this.buttonG.position.y || mouseY > (_this.buttonG.position.y+_this.buttonG.box.height))
         {
            _this.buttonG.changeOut();
         }
         if (mouseX > _this.buttonM.position.x && mouseX < (_this.buttonM.position.x+_this.buttonM.box.width) && mouseY > _this.buttonM.position.y && mouseY < (_this.buttonM.position.y+_this.buttonM.box.height))
        {
           _this.buttonM.changeIn();
         }
        if (mouseX < _this.buttonM.position.x || mouseX > (_this.buttonM.position.x+_this.buttonM.box.width) || mouseY < _this.buttonM.position.y || mouseY > (_this.buttonM.position.y+_this.buttonM.box.height))
         {
            _this.buttonM.changeOut();
         }
     }
     
	_this.keyDown = function(e){
		
	}
	
	// 这个函数用来清理资源
	_this.clearUp = function(){
	    _this.logic.sceneManager.clearNodeList();
//		_this.mark.FreeImgList();
	}
	// 这个函数用来查询ready状态.
	_this.ready = function(){
		return _this.bg.ready && _this.buttonM.ready && _this.buttonG.ready;
	}
	
	var init = function () 
	{   
//		_this.mark = new Mark(new Vector2(360, 150), new Rectangle(54, 56));
	    _this.bg = new Bg(new Vector2(0,0), new Rectangle(480, 768));
        _this.bg.img.src = "./images/over.png";
             
        _this.buttonG = new ChangeButton(new Vector2(120, 445), new Rectangle(256, 59));
		_this.buttonG.img.src = "./images/Retry.png";
        _this.buttonG.src_1 = "./images/Retry.png";
        _this.buttonG.src_2 = "./images/Retry_h.png";
        
        _this.buttonM = new ChangeButton(new Vector2(120, 520), new Rectangle(256, 59));
		_this.buttonM.img.src = "./images/OverToMenu.png";
        _this.buttonM.src_1 = "./images/OverToMenu.png";
        _this.buttonM.src_2 = "./images/OverToMenu_h.png";   
		
		_this.scoreBoard = new ScoreBoard(new Vector2(120, 150), new Rectangle(54,56), 1);
		_this.scoreBoard.update(marks);
		 
	}
	init();
}